namespace DotNetNuke.Framework.Providers
{
    using DotNetNuke.Common.Utilities;
    using System;
    using System.Collections;
    using System.Xml;

    public class ProviderConfiguration
    {
        private string _DefaultProvider;
        private Hashtable _Providers = new Hashtable();

        public static ProviderConfiguration GetProviderConfiguration(string strProvider)
        {
            return (ProviderConfiguration) Config.GetSection("dotnetnuke/" + strProvider);
        }

        internal void GetProviders(XmlNode node)
        {
            IEnumerator refObjectHelperL0=null;
            try
            {
                refObjectHelperL0 = node.ChildNodes.GetEnumerator();
                while (refObjectHelperL0.MoveNext())
                {
                    XmlNode Provider = (XmlNode) refObjectHelperL0.Current;
                    switch (Provider.Name)
                    {
                        case "add":
                            this.Providers.Add(Provider.Attributes["name"].Value, new Provider(Provider.Attributes));
                            break;

                        case "remove":
                            this.Providers.Remove(Provider.Attributes["name"].Value);
                            break;

                        case "clear":
                            this.Providers.Clear();
                            break;
                    }
                }
            }
            finally
            {
                if (refObjectHelperL0 is IDisposable)
                {
                    (refObjectHelperL0 as IDisposable).Dispose();
                }
            }
        }

        internal void LoadValuesFromConfigurationXml(XmlNode node)
        {
            IEnumerator refObjectHelperL0=null;
            XmlAttributeCollection attributeCollection = node.Attributes;
            this._DefaultProvider = attributeCollection["defaultProvider"].Value;
            try
            {
                refObjectHelperL0 = node.ChildNodes.GetEnumerator();
                while (refObjectHelperL0.MoveNext())
                {
                    XmlNode child = (XmlNode) refObjectHelperL0.Current;
                    if (child.Name == "providers")
                    {
                        this.GetProviders(child);
                    }
                }
            }
            finally
            {
                if (refObjectHelperL0 is IDisposable)
                {
                    (refObjectHelperL0 as IDisposable).Dispose();
                }
            }
        }

        public string DefaultProvider
        {
            get
            {
                return this._DefaultProvider;
            }
        }

        public Hashtable Providers
        {
            get
            {
                return this._Providers;
            }
        }
    }
}

